package com.qipay.api;

import com.qipay.core.security.passwordencoder.MD5PasswordEncoder;
import com.qipay.security.jwt.JWTUserDetailsServiceImpl;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * Created by Administrator on 2017/4/26.
 */
@SpringBootApplication
@EnableTransactionManagement
@EnableAutoConfiguration
@ComponentScan(basePackages = "com.qipay")
@MapperScan({"com.qipay.mapper","com.qipay.core.mapper"})
@EnableScheduling
public class ApiApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ApiApplication.class);
    }

    public static void main(String[] args) {
       SpringApplication.run(ApiApplication.class, args);

//        SpringContextUtil util = new SpringContextUtil();
//        util.setApplicationContext(applicationContext);
    }

    @Bean
    public PasswordEncoder passwordEncoder(){
        return new MD5PasswordEncoder();
    }

    @Bean
    public UserDetailsService userDetailsService() {
        return new JWTUserDetailsServiceImpl();
    }


}
